package top.drinyeit.nongmao.presenter;

import java.util.List;

import top.drinyeit.nongmao.activity.PaymentDetailsActivity;
import top.drinyeit.nongmao.adapter.PaymentDetailsAdapter;
import top.drinyeit.nongmao.app.Constant;
import top.drinyeit.nongmao.model.BalanceDetailBean;
import top.drinyeit.nongmao.retrofit.HttpResponse;
import top.drinyeit.nongmao.retrofit.RetrofitMethod;
import top.drinyeit.nongmao.retrofit.subscriber.CommonSubscriber;
import top.drinyeit.nongmao.retrofit.subscriber.SubscriberListener;
import top.drinyeit.nongmao.util.SPUtil;

import static top.drinyeit.nongmao.app.Constant.COMMON_SUCCESS;

/**
 * Created by wu on 2018/1/6.
 */

public class PaymentDetailsPresenter {
    private PaymentDetailsActivity activity;

    public PaymentDetailsPresenter(PaymentDetailsActivity activity){
        this.activity = activity;
    }
    //获取用户余额收支明细
    public void getBlDe() {
        String user_id = SPUtil.getShareString(Constant.USER_ID);
        activity.showLoading();
        CommonSubscriber<HttpResponse<List<BalanceDetailBean>>> subscriber = new CommonSubscriber<>(new SubscriberListener<HttpResponse<List<BalanceDetailBean>>>() {
            @Override
            public void onError(String e, int code) {
                activity.dismissLoading();
                activity.showToastMsg("错误，请重新操作！");
            }

            @Override
            public void onNext(HttpResponse<List<BalanceDetailBean>> o) {
                activity.dismissLoading();
                if (o.getCode() == COMMON_SUCCESS) {
                    activity.getList().addAll(o.getData());
                    ((PaymentDetailsAdapter)activity.getPay_ListView().getAdapter()).notifyDataSetChanged();
                }else {

                }
            }
        });
        RetrofitMethod.getInstance().getBlDe(subscriber, user_id);
    }
}
